package com.example.anday3.adapter;

import android.content.Context;
import android.media.Image;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.bumptech.glide.Glide;
import com.example.anday3.R;
import com.example.anday3.pojo.GoodsResData;

import java.util.List;

public class GoodsAdapter extends ArrayAdapter<GoodsResData.ListGoods> {
    public GoodsAdapter(@NonNull Context context,  @NonNull List<GoodsResData.ListGoods> objects) {
        super(context, R.layout.listitem, objects);
    }

    @NonNull
    @Override
    public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
       if(convertView==null){
           convertView= LayoutInflater.from(getContext()).inflate(R.layout.listitem,parent,false);
       }
        GoodsResData.ListGoods goods=getItem(position);
        ImageView img=convertView.findViewById(R.id.img);
        TextView textView=convertView.findViewById(R.id.name);
        TextView price=convertView.findViewById(R.id.price);
        Glide.with(getContext()).load(goods.getGoodsImg()).into(img);
        textView.setText(goods.getGoodsName());
        price.setText(String.valueOf(goods.getMarketPrice()));

       return convertView;
    }
}
